
/**
 * Created by Mj on 2017/9/5.
 * 公共类
 */
var Util = {
	//get
	get: function(url, data, callback) {
			$.ajax({
				url: url,
				type: "get",
				data: data,
				dataType: "json",
				beforeSend: function() {
					//数据正在加载
				},
				success: function(res) {
					//加载成功
					console.log(res);
					callback(res);
				},
				error: function() {
					//加载失败
				}
			});
	},
	//post
	post: function(url, data, callback) {
			data = JSON.stringify(data),
			$.ajax({
				url: url,
				data: data,
				type: 'post',
				dataType: 'json',
				contentType: 'application/json; charset=utf-8',
				beforeSend: function() {
					//数据正在加载
				},
				success: function(res) {
					//加载成功
					callback(res);
				},
				error: function() {
					//加载失败
				}
			});
	},
	//获取url参数
	GetQueryString: function(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if(r != null)
			return unescape(r[2]);
		return null;
	},

	//时间戳
	UnixToDate: function(unixTime, isFull, timeZone) {
		if(typeof(timeZone) == 'number') {
			unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
		}
		var time = new Date(unixTime * 1000);
		var ymdhis = "";
		ymdhis += time.getUTCFullYear() + "-";
		ymdhis += (time.getUTCMonth() + 1) + "-";
		ymdhis += time.getUTCDate();
		if(isFull === true) {
			ymdhis += " " + time.getUTCHours() + ":";
			ymdhis += time.getUTCMinutes() + ":";
			ymdhis += time.getUTCSeconds();
		}
		return ymdhis;
	},
	// 跳转
	jump: function(url) {
		window.location.href = url;
	},
	// 返回上一页
	back: function() {
		window.history.go(-1);
	},
	trim: function(str) { //去除左右两边空格
		return str.replace(/(^\s*)|(\s*$)/g, ""); 
	},
	// 分页
	Pinterest: function(callback) {
		var hasmore = true
		$(window).scroll(function() {
			let arr = [];
			arr = $('.head_time');
			var down = $(document).height() - $(document).scrollTop() - $(window).height();
			for(let i = 0; i < arr.length; i++){
				let hight = $(arr[i]).offset().top-$(window).scrollTop();
				if(hight<25){
					$(arr[i]).addClass('top');
					$(arr[i]).next('.item').css('margin-top','0.5rem');
					$('.head_time').not($(arr[i])).removeClass('top');
					$('.head_time').not($(arr[i])).next('.item').css('margin-top','0');
				}
			} 
			if(down <= 50 && hasmore == true) {
				hasmore = false;
				if(callback)
					callback();
			}
			if(down > 50) {
				hasmore = true
			}
		})
	},
	
	
	// 新版账单列表分页
	orderList: function(callback) {
		var hasmore = true
		$(window).scroll(function() {
			let arr = [];
			arr = $('.head_time');
			var down = $(document).height() - $(document).scrollTop() - $(window).height();
			for(let i = 0; i < arr.length; i++){
				let hight = $(arr[i]).offset().top-$(window).scrollTop();
				if(hight<25){
					$(arr[i]).addClass('top');
					$(arr[i]).next('.item').css('margin-top','0.5rem');
					$('.head_time').not($(arr[i])).removeClass('top');
					$('.head_time').not($(arr[i])).next('.item').css('margin-top','0');
				}
			} 
			if(down <= 50 && hasmore == true) {
				hasmore = false;
				if(callback)
					callback();
			}
			if(down > 50) {
				hasmore = true
			}
		})
	},
	
	//img2base64
	ImgToBase64: function(file, maxLen, callBack){
		var img = new Image();
	    var reader = new FileReader();//读取客户端上的文件
	    reader.onload = function () {
	        var url = reader.result;//读取到的文件内容.这个属性只在读取操作完成之后才有效,并且数据的格式取决于读取操作是由哪个方法发起的.所以必须使用reader.onload，
	        img.src = url;//reader读取的文件内容是base64,利用这个url就能实现上传前预览图片
	    };
	    img.onload = function () {
	        //生成比例
	        var width = img.width, height = img.height;
	        //计算缩放比例
	        var rate = 1;
	        if (width >= height) {
	            if (width > maxLen) {
	                rate = maxLen / width;
	            }
	        } else {
	            if (height > maxLen) {
	                rate = maxLen / height;
	            }
	        };
	        img.width = width * rate;
	        img.height = height * rate;
	        //生成canvas
	        var canvas = document.createElement("canvas");
	        var ctx = canvas.getContext("2d");
	        canvas.width = img.width;
	        canvas.height = img.height;
	        ctx.drawImage(img, 0, 0, img.width, img.height);
	        var base64 = canvas.toDataURL('image/jpeg', 0.9);
	        callBack(base64);
	    };
	    reader.readAsDataURL(file);
	},
	
	//产生随机数
	generateMixed: function(n){
		var chars = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
		 var res = "";
	     for(var i = 0; i < n ; i ++) {
	         var id = Math.ceil(Math.random()*35);
	         res += chars[id];
	     }
	     return res;
	},
	
	//获取当前年月日
	getTime: function(){
				var nowdate = new Date();  
		        var y = nowdate.getFullYear();  
		        var m = nowdate.getMonth()+1;  
		        var d = nowdate.getDate();  
		        var formatnowdate = y+'-'; 
		         if(m < 10)
	            formatnowdate += "0";
		        formatnowdate += m + "-";
		        if(d < 10)
		            formatnowdate += "0";
		        formatnowdate += d;
		        return formatnowdate;
	},
	
	//获取一周前年月日
	getWeekTime: function(){
				var nowdate = new Date();
				var oneweekdate = new Date(nowdate-6*24*3600*1000);  
		        var y = oneweekdate.getFullYear();  
		        var m = oneweekdate.getMonth()+1;  
		        var d = oneweekdate.getDate();
		         var formatwdate = y+'-'; 
				if(m < 10)
	            formatwdate += "0";
		        formatwdate += m + "-";
		        if(d < 10)
		            formatwdate += "0";
		        formatwdate += d;
		        return formatwdate;
	},
	
	//获取当前年份
	getYearTime: function(){
				var nowdate = new Date();  
		        var y = nowdate.getFullYear();
		        return y;
	},
	
	//删除数组指定元素
	removeObjWithArr: function(_arr,_obj){
		  var length = _arr.length;
		    for(var i = 0; i < length; i++)
		    {
		        if(_arr[i] == _obj)
		        {
		            if(i == 0)
		            {
		                _arr.shift(); //删除并返回数组的第一个元素
		                return;
		            }
		            else if(i == length-1)
		            {
		                _arr.pop();  //删除并返回数组的最后一个元素
		                return;
		            }
		            else
		            {
		                _arr.splice(i,1); //删除下标为i的元素
		                return;
		            }
		        }
		    }
	},
	
	//判断通道是否可用数组排序
	compareArr: function(property){
		  return function(a,b){
			        var value1 = a[property];
			        var value2 = b[property];
			        return value2 - value1;
		  }
	},
	
	// 判断当前时间是否在可用时间范围内
	time_range: function(beginTime,endTime){
	   var strb = beginTime.split (":");
		  if (strb.length != 2) {
		    return false;
		  }
		 
		  var stre = endTime.split (":");
		  if (stre.length != 2) {
		    return false;
		  }
		 
		  var b = new Date ();
		  var e = new Date ();
		  var n = new Date ();
		 
		  b.setHours (strb[0]);
		  b.setMinutes (strb[1]);
		  e.setHours (stre[0]);
		  e.setMinutes (stre[1]);
		 
		  if (n.getTime () - b.getTime () > 0 && n.getTime () - e.getTime () < 0) {
		    return true;
		  } else {
		    return false;
		  }
	}
}
//获取数据渲染数据
var Public = {
	findPage_y:true, //下拉加载时判断
	findPage_key:false, //下拉加载时判断
	getBankInfo:function(data, callback) {//根据银行卡号获取银行信息
		Util.post(API.getBankInfo, data, function(res) {
			if(res.code == 200) {
				if(callback)
					callback(res)
			} else {
				layer.open({
					content:res.message,
						skin: 'msg',
						time: 2 //2秒后自动关闭
					});
			}
		});
	},
	bundQuickBankCard:function(data, callback) {//添加绑定银行卡
		Util.post(API.bundQuickBankCard, data, function(res) {
			console.log(res);
			if(res.code == 200) {
				if(callback)
					callback(res)
			} else {
				layer.open({
					content:res.message,
						skin: 'msg',
						time: 2 //2秒后自动关闭
					});
			}
		});
	},
	gateway:function(data, callback) {//获取支付列表
		Util.post(API.gateway, data, function(res) {
			if(res.code == 200) {
				var imgArr = new Array();
				for(var i=0; i<res.data.length; i++){
					imgArr[i] = new Array();
					imgArr[i]= res.data[i].icon.split(',');
					res.data[i].icon = imgArr[i];
				}
				if(callback)
					callback(res)
			} else {
			}
		});
	},
	ChangePayByHome:function(data, callback) {//#降低费率页面#切换支付方式拉取列表
		Util.post(API.gateway, data, function(res) {
			console.log(res);
			if(res.code == 200) {
				if(callback)
					callback(res)
			} else {
			}
		});
	},
	ChangePayByRece:function(data, callback) {//#收款页面#支付方式拉取列表
		Util.post(API.gateway, data, function(res) {
			console.log(res);
			if(res.code == 200) {
				var imgArr = new Array();
				for(var i=0; i<res.data.length; i++){
					imgArr[i] = new Array();
					imgArr[i]= res.data[i].icon.split(',');
					res.data[i].icon = imgArr[i];
				}
				if(callback)
					callback(res)
			} else {
			}
		});
	},
	Confirm:function(data, callback) {//#收款页面#确认按钮拉取银行等信息
		Util.post(API.gateway, data, function(res) {
			var modelMoney = $('#money').html()*100;
			if(res.code == 200) {
				for(var i=0; i<res.data.unionBank.length; i++){
						var str = res.data.unionBank[i].acctNo
						res.data.unionBank[i].acctNo= str.substr(str.length-4);
					}
					// 判断用户输入金额在那些通道可用
					for(var i=0; i<res.data.channels.length;i++){
						if(res.data.channels[i].tradeMinAmt<= modelMoney && modelMoney <= res.data.channels[i].tradeMaxAmt && res.data.channels[i].enabled == 1 && Util.time_range(res.data.channels[i].startTime,res.data.channels[i].endTime)){ //输入金额可用通道
							res.data.channels[i].available = true; //通道是否可用
						}else{ // 输入金额不可用通道，并重新封装数据
							res.data.channels[i].available = false; //通道是否可用
						}
					}
					// 按是否可用排序
					res.data.channels = res.data.channels.sort(Util.compareArr('available'));
					if(callback)
						callback(res)
			} else {
			}
		});
	},
	GetBankCard:function(data) {//#收款页面#确认按钮拉取银行等信息
		Util.post(API.gateway, data, function(res) {
			if(res.code == 200) {
					for(var i=0; i<res.data.length; i++){
					var str = res.data[i].acctNo
					res.data[i].acctNo= str.substr(str.length-4);
				}
			html = template.render("template_bankCard", res);
			$("#bankCard").html(html);
			var myScroll = new IScroll('#wrapper', {mouseWheel: true,click: true,tap: true});
			} else {
			}
		});
	},
	detail:function(data, callback) {//#降低费率页面#切换支付方式拉取列表
		Util.post(API.detail, data, function(res) {
			if(res.code == 200) {
				res.data.actualAmount = (res.data.actualAmount/100).toFixed(2);
				res.data.orderAmount = (res.data.orderAmount/100).toFixed(2);
				if(callback)
					callback(res)
			} else {
			}
		});
	},
	info:function(data, callback) {//桌牌码
		Util.post(API.info, data, function(res) {
			console.log(res);
			if(res.code == 200) {
				if(callback)
					callback(res)
			} else {
			}
		});
	},
	findSubBank:function(data, callback) {//获取银行支行网点
		Util.post(API.findSubBank, data, function(res) {
			console.log(res);
			if(res.code == 200) {
				if(callback)
					callback(res)
			} else {
			}
		});
	},
	industryMap: function(callback) {//获取行业类别
		Util.post(API.industryMap,{}, function(res) {
			if(res.code == 200) {
			var arr = res.data;
			var map = {},root = [];
			for(var i = 0; i < arr.length; i++){
			    var ai = arr[i];
			    if(!map[ai.category]){
			        root.push({
			        	code: i,
			            name: ai.category,
			            child: [ai]
			        });
			        map[ai.category] = ai;
			    }else{
			        for(var j = 0; j < root.length; j++){
			            var dj = root[j];
			            if(dj.name == ai.category){
			                dj.child.push(ai);
			                break;
			            }
			        }
			    }
			}
				if(callback)
					callback(root)
			} else {
			}
		});
	},
	areaMap:function(callback) {//获取区域列表
		root = [], allAreaObj = {};
		Util.post(API.areaMap,{},function(res) {
			if(res.code == 200) {
				var list = res.data;
				if(list != null && list.length > 0){
					for(var i = 0; i < list.length; i++){
						var item = list[i], parentCode = item.parentCode;
						allAreaObj[item.code] = item;
						if(parentCode == ''){
							root.push(item);
							continue;
						}
						var parentArea = allAreaObj[parentCode];
						var children = parentArea.child;
						if(children === undefined){
							children = [];
						}
						children.push(item);
						parentArea['child'] = children;
					}
				}
				if(callback)
					callback(root);
			} else {
			}
		});
	},
	settleCardAuth:function(data, callback) {//结算卡认证
		Util.post(API.settleCardAuth, data, function(res) {
			if(res.code == 200) {
				if(callback)
					callback(res)
			} else {
			  layer.open({
					content: res.message,
							skin: 'msg',
							time: 2 //2秒后自动关闭
					});
			}
		});
	},
	shopAuth: function(data, callback) {//店铺认证
		Util.post(API.shopAuth, data, function(res) {
			if(res.code == 200) {
				if(callback)
					callback(res)
			} else {
			  layer.open({
					content: res.message,
							skin: 'msg',
							time: 2 //2秒后自动关闭
					});
			}
		});
	},
	getWechatSign: function(data,callback) {//获取签名
		Util.get(API.getWechatSign,data,function(res) {
			console.log(res);
				if(callback)
					callback(res)
		});
	},
	getLatelyAuth:function(data, callback) {//获取用户认证信息
		Util.post(API.getLatelyAuth, data, function(res) {
			if(res.code == 200) {
				if(callback)
					callback(res)
			} else {
			}
		});
	},
	upload:function(data, callback) {//微信上传图片
		Util.post(API.upload, data, function(res) {
			layer.open({type: 2});
			if(res.code == 200) {
				layer.closeAll();
				if(callback)
					callback(res)
			} else {
				layer.closeAll();
				layer.open({
					content: res.message
					,skin: 'msg'
					,time: 2 
				});
			}
		});
	},
	realNameAuth:function(data, callback) {//实名认证
		Util.post(API.realNameAuth, data, function(res) {
			console.log(res);
			if(res.code == 200) {
				if(callback)
					callback(res)
			} else {
					layer.open({
					content: res.message
					,skin: 'msg'
					,time: 2 //2秒后自动关闭
				});
			}
		});
	},
	merchantAuth:function(data, callback) {//商户认证
		Util.post(API.merchantAuth, data, function(res) {
			layer.open({
					content: res
					,skin: 'msg'
					,time: 2 //2秒后自动关闭
				});
				console.log(res);
			if(res.code == 200) {
				if(callback)
					callback(res)
			} else {
				layer.open({
					content: res.message
					,skin: 'msg'
					,time: 2 //2秒后自动关闭
				});
			}
		});
	},
	identity:function(data, callback) {//ocr 识别身份证正反面
		Util.post(API.identity, data, function(res) {
			if(res.code == 200) {
				if(callback)
					callback(res)
			} else {
				layer.open({
					content: res.message
					,skin: 'msg'
					,time: 2 //2秒后自动关闭
				});
			}
		});
	},
	findPage:function(data) { //收款记录
		Util.post(API.findPage, data, function(res) {
			if(res.code == 200) {
				console.log(res);
			if(res.data.length == 0 && Public.findPage_y && Public.findPage_key){
				var html ="<p style='text-align: center;padding: 10px 0;width: 100%;'>—— 别扯了, 到底啦 ——</p>";
				$('#orderList').append(html);
				Public.findPage_y = false;
				Public.findPage_key = true;
			}else if(res.data.length == 0 && !Public.findPage_key){
				var html =' <div class="zanwulogo"><img src="img/zanwulogo.png" alt="" /><p>目前暂无数据</p></div>';
				$('#orderList').append(html);
			}
			for(var i = 0; i<res.data.length; i++){ //截取时间，作为分组识别
				var str = res.data[i].createTime;
				res.data[i].timeId = str.substr(0,10); 
				res.data[i].orderAmount = (res.data[i].orderAmount/100).toFixed(2);
			}
			var arr = res.data;
			var map = {},root = [];
			for(var i = 0; i < arr.length; i++){
			    var ai = arr[i];
			    if(!map[ai.timeId]){
			        root.push({
			        	code: i,
			            timeId: ai.timeId,
			            child: [ai]
			        });
			        map[ai.timeId] = ai;
			    }else{
			        for(var j = 0; j < root.length; j++){
			            var dj = root[j];
			            if(dj.timeId == ai.timeId){
			                dj.child.push(ai);
			                break;
			            }
			        }
			    }
			}
			var res = {};
		 	res.data = root;
			html = template.render("template_orderList", res);
			$('#orderList').append(html);
			Public.findPage_key = true;
			} else {
					layer.open({
					content: res.message
					,skin: 'msg'
					,time: 2 //2秒后自动关闭
				});
			}
		});
	},
	getBillRecordList: function(data, callback) {// 新版账单明细
		Util.post(API.gateway, data, function(res) {
			if(res.code == 200) {
			console.log(res);
			if(res.data.groups.length == 0 && Public.findPage_y && Public.findPage_key){
				var html ="<p style='text-align: center;padding: 10px 0;width: 100%;font-size:0.3rem'>—— 别扯了, 到底啦 ——</p>";
				$('#orderList').append(html);
				Public.findPage_y = false;
				Public.findPage_key = true;
			}else if(res.data.groups.length == 0 && !Public.findPage_key){
				var html =' <div class="zanwulogo"><img src="img/zanwulogo.png" alt="" /><p>目前暂无数据</p></div>';
				$('#orderList').append(html);
			}
			html = template.render("headbox_template", res);
			$('#headBox').html(html);
			res.data = res.data.groups;
			console.log(res);
				html = template.render("template_orderList", res);
				$('#orderList').append(html);
				Public.findPage_key = true;
				if(callback)
					callback(res)
			} else {
				layer.open({
					content: res.message
					,skin: 'msg'
					,time: 2 //2秒后自动关闭
				});
			}
		});
	},
	getYearProfit: function(data, callback) {//收益明细 获取每月收益
		Util.post(API.gateway, data, function(res) {
			console.log(res);
			if(res.code == 200) {
				var first = [], last = [], year = [], YearCount = 0;
				for(var i in res.data.queryList){
					YearCount += parseFloat(res.data.queryList[i].amount);
					first =  res.data.queryList[i].firstDay.split('-');
					last =  res.data.queryList[i].lastDay.split('-');
					year = res.data.queryList[i].month.split('-');
					res.data.queryList[i].firstDay = first[1]+'月'+first[2]+'日';
					res.data.queryList[i].lastDay = last[1]+'月'+last[2]+'日';
					res.data.queryList[i].month = year[0]+'年'+year[1]+'月收益';
				}
				res.data.currentYearCount = YearCount.toFixed(2);
				if(callback)
					callback(res)
			} else {
				layer.open({
					content: res.message
					,skin: 'msg'
					,time: 2 //2秒后自动关闭
				});
			}
		});
	},
	getProfitList: function(data, callback) {//收益明细 获取每月收益
		Util.post(API.gateway, data, function(res) {
			if(res.code == 200) {
				if(callback)
					callback(res)
			} else {
				layer.open({
					content: res.message
					,skin: 'msg'
					,time: 2 //2秒后自动关闭
				});
			}
		});
	},
	sdkPay: function(data, callback){ //支付类型为03的sdk调起支付
		Util.post(API.gateway, data, function(res) {
			layer.closeAll("loading");
			if(res.code == 200) {
				if(callback)
					callback(res)
			} else {
				layer.open({
					content: res.message
					,skin: 'msg'
					,time: 2 //2秒后自动关闭
				});
			}
		});
	}
}
//页面交互,dom操作
var Vim = {
	/**
	 * 降低费率 lowerRates.html
	 * 
	 * */
	//切换支付方式拉取列表
	ChangePayByHome: function(that){
		var userId = localStorage.userId;
		var payType = $(that).data('paytype');
		Public.ChangePayByHome({
			method:"product.rate.list",
			userId:userId,
			payTradeWay:payType,
			productType:0,
			version:"1.0.2"
		},function(res){
			html = template.render("template_Receivablesboxlist", res);
			$('#Receivablesboxlist').html(html);
		});
	},
	/**
	 * 降低费率 mypassageway.html
	 * 
	 * */
	//切换支付方式拉取列表
	ChangePayByMypassageway:function(that){
		var userId = localStorage.userId;
		var payType = parseInt($(that).data('paytype'));
			Public.ChangePayByHome({
				method:"channel.have.search",
				userId:userId,
				payTradeWay:payType,
				productType:0,
				version:"1.0.2"
		},function(res){
			html = template.render("template_Receivablesboxlist", res);
			$('#Receivablesboxlist').html(html);
		});
	},
}

//认证中心相关响应事件
var Auth = {
	
	realNameAuth: function(){ //实名认证
		console.log(needExamine);
		var userName = $('#Username').val();
		var cardNo_number = $('#cardNo_number').val();
		var areaNames = $('#dizhi').val();
		var areaCodes = $('#dizhikey').val();
		var address = $('#user_address').val();
		if(card1 == undefined || card1 == undefined || card3 == undefined){
			layer.open({content: '请上传身份证认证照片',skin: 'msg',time: 2});
		}else if(areaNames == '' || areaCodes ==''){
			layer.open({content: '请选择身份证地区',skin: 'msg',time: 2});
		}else if(cardNo_number == '' || userName == '' || address == ''){
			layer.open({content: '请核实相关信息是否填写完整',skin: 'msg',time: 2});
		}else{
				Public.realNameAuth({
					userId: localStorage.userId,
					fullName: userName,
					cardType: 0,
					cardNo: cardNo_number,
					areaCodes: areaCodes,
					areaNames: areaNames,
					address: address,
					card1: card1,
					card2: card2,
					card3: card3,
					needExamine:needExamine
		},function(res){
			layer.open({content: '实名认证提交成功',skin: 'msg',time: 2});
		})
		}
	},
	
	shopAuth: function(){ //提交店铺认证
		var authType = $('#authType option:selected').val(); //获取认证类型
		var shopName = $('#shopName').val(); //商户名称
		var areaNames = $('#shopAuth').val(); //经营地址
		var areaCodes = $('#shopAuthkey').val(); 
		var address = $('#address').val(); //经营详细地址
		if(shopName == ''){
			layer.open({content: '商户名称不能为空',skin: 'msg',time: 2});
		}else if(areaNames == ''){
			layer.open({content: '经营地址不能为空',skin: 'msg',time: 2});
		}else if(address == ''){
			layer.open({content: '详细地址不能为空',skin: 'msg',time: 2});
		}else{
		Public.shopAuth({
			userId:localStorage.userId, //用户userId
			shopName:shopName, //店铺名
			areaCodes:areaCodes, //经营地址code
			areaNames:areaNames, //经营地址
			address:address, //经营详细地址
			authType:authType //店铺类型
		},function(res){
			layer.open({content: '店铺认证提交成功!',skin: 'msg',time: 2});
		});
		}
	},
	
	settleCardAuth: function(){ //提交结算卡认证
		var accName = $('#accName').val(); //持卡人姓名
		var accNo = $('#accNo').val(); //结算卡卡号
		var bankName = $('#bankName').val(); //结算卡开户行
		var bankCity = $('#bankCity').val(); //开户城市
		var bankCitykey = $('#bankCitykey').val(); //开户城市代码
		var bankzName = $('#bankzName').val(); //开户支行名
		var phoneNo = $('#phoneNo').val(); //预留手机号码
		if(accName == ''){
				layer.open({content: '先实名认证后，方可结算卡认证',skin: 'msg',time: 2});
		}else if(accNo.length<16 || accNo == ''){
			layer.open({content: '卡号至少16位',skin: 'msg',time: 2});
		}else if(bankCity == ''){
			layer.open({content: '开户城市不能为空',skin: 'msg',time: 2});
		}else if(bankzName == ''){
			layer.open({content: '开户支行不能为空',skin: 'msg',time: 2});
		}else if(!phoneNo.match(/^(1)[0-9]{10}$/)){
			layer.open({content: '预留手机号不合法',skin: 'msg',time: 2});
		}else{
			Public.settleCardAuth({
				userId: localStorage.userId, //用户userId
				customerName: accName, //持卡人姓名
				certId: localStorage.cardNo, //身份证号码
				bankId: localStorage.accbankId, //银行id
				bankName: bankName, //银行名称
				subBankName: bankzName, //支行名称
				acctNo: accNo, //银行卡号
				phoneNo: phoneNo, //预留手机号
				areaCodes: bankCitykey, //开户城市编码
				areaNames: bankCity, //开户城市
				accountType: 2
			},function(res){
				layer.open({
					content:'结算卡认证提交成功!',
							skin: 'msg',
							time: 2 //2秒后自动关闭
					});
			});
		}		
	},
	
	creditClick: function(){ //提交信用卡认证资料
		var creditName = $('#creditName').val(); //持卡人姓名
		var creditNo = $('#creditNo').val(); //信用卡号
		var lastNo = $('#lastNo').val(); //信用卡背后面3位数
		var effectiveNo = $('#effectiveNo').val(); //有效期
			effectiveNoStr = effectiveNo.substring(2)+effectiveNo.substring(0,2);
		var creditPhone = $('#creditPhone').val(); //预留手机号码
		Public.getBankInfo({ //根据银行卡号查询银行名称
				bankno: creditNo,
				isCredit: true //新增参数
				},function(res){
					if(creditName == ''){
						layer.open({content: '先实名认证后，方可信用卡认证',skin: 'msg',time: 2});	
					}else if(creditNo.length<16 || creditNo == ''){
						layer.open({content: '卡号至少16位',skin: 'msg',time: 2});	
					}else if(lastNo == ''){
						layer.open({content: '安全码不能为空',skin: 'msg',time: 2});
					}else if(effectiveNo == ''){
						layer.open({content: '有效期不能为空',skin: 'msg',time: 2});
					}else if(!creditPhone.match(/^(1)[0-9]{10}$/)){
						layer.open({content:'预留手机号码不合法',skin: 'msg',time: 2});
					}else{
						Public.bundQuickBankCard({
							userId: localStorage.userId, //userId
							bankId: res.data.id, //银行卡id
							customerName: creditName, //持卡人姓名
							certId: localStorage.cardNo, //身份证号
							bankName: res.data.bankName, //银行卡名
							acctNo: creditNo, //开户银行卡号
							phoneNo: creditPhone, //预留手机号
							cardType: '22', //指定信用卡
							expDate: effectiveNoStr, //过期时间
							cvn2: lastNo //安全码
						},function(res){
							layer.open({content:'信用卡认证提交成功!',skin: 'msg',time: 2});
						});
					}		
			});
	},
	
	merchantAuth: function(){ //商户认证
		var mchDealType = $('#mchDealType option:selected').val(); //商户类型
		var industrName = $('#industry').val(); //行业类别
		    industrName = industrName.split(',')[1];
		 var industrId = $('#industrykey').val(); //行业类别编号
		    industrId = industrId.split(',')[1];
		 var licenseNo = $('#licenseNo').val(); //营业执照编号
		 var legalPerson = $('#legalPerson').val();
		 var customerPhone = $('#customerPhone').val();
		 var email = $('#email').val();
		 if(industrId == ''){
		 	layer.open({
				content:'请选择行业类别',skin: 'msg',time: 2});
		 }else if(licenseNo == ''){
		 	layer.open({
				content:'请输入营业执照编号',skin: 'msg',time: 2});
		 }else if(!email.match(/^(.+)@(.+)$/)){
		 	layer.open({
				content:'邮箱不合法',skin: 'msg',time: 2});
		 }else if(customerPhone == ''){
		 	layer.open({
				content:'客服电话不能为空',skin: 'msg',time: 2});
		 }else{
		 	Public.merchantAuth({
					userId:localStorage.userId, //用户userId
					mchDealType:mchDealType, 
					industrId:industrId,
					industrName:industrName,
					licenseNo:licenseNo,
					licensePhoto:licensePhoto,//营业执照
					facadePhoto:facadePhoto,//门头照
					email: email,//法人邮箱
					legalPerson:legalPerson, //法人
					customerPhone:customerPhone //客服电话
			},function(res){
				layer.open({
					content:'商户认证提交成功!',skin: 'msg',time: 2});
			});
		 }
	},
	
	Authjump: function(){
		var bankCitykey = $('#bankCitykey').val();
		var bankCity = $('#bankCity').val();
		sessionStorage.bankCitykey = bankCitykey;
		sessionStorage.bankCity = bankCity;
		if(bankCitykey == ''){
			layer.open({content:'请选择开户城市',skin: 'msg',time: 2});
		}else{
			var cityCode = bankCitykey.split(',')[1];
			Util.jump('choiceBankList.html?cityCode='+cityCode);
		}
	},
	
	
}
